package guilayer;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

//import controllayer.ProductCtrl;

public class ProductLookup extends AbstractSetProduct {
	//private CustomerCtrl customerCtrl;
	private JTextField txtProductBarcode;
	private JTextField txtProductLabel;
	private JTextField txtProductPrice;
	private JLabel lblProductBarcode;
	private JLabel lblProductLabel;
	private JLabel lblProductPrice;
	private JPanel panel;
	private JButton btnEditProduct;
	private JButton btnDeleteProduct;

	/**
	 * Create the panel.
	 */
	public ProductLookup() {
		super();
	}
	public ProductLookup(String barcode) {
		super(barcode);
	}

	@Override
	protected JPanel loadThePage() {
		setLayout(new BorderLayout(0, 0));
		
		JPanel pnlForm = new JPanel();
		// Remove the background
		pnlForm.setOpaque(false);
		add(pnlForm, BorderLayout.CENTER);
		pnlForm.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC}));
		
		lblProductBarcode = new JLabel("Stregkode:");
		pnlForm.add(lblProductBarcode, "2, 2, left, default");
		
		txtProductBarcode = new JTextField();
		txtProductBarcode.setEditable(false);
		txtProductBarcode.setEnabled(false);
		txtProductBarcode.setText(product.getBarcode());
		pnlForm.add(txtProductBarcode, "4, 2, fill, default");
		txtProductBarcode.setColumns(10);
		
		lblProductLabel = new JLabel("Produkt navn:");
		pnlForm.add(lblProductLabel, "2, 4, left, default");
		
		txtProductLabel = new JTextField();
		txtProductLabel.setEditable(false);
		txtProductLabel.setEnabled(false);
		txtProductLabel.setText(product.getProductLabel());
		pnlForm.add(txtProductLabel, "4, 4, fill, default");
		txtProductLabel.setColumns(10);
		
		lblProductPrice = new JLabel("Pris:");
		pnlForm.add(lblProductPrice, "2, 6, left, default");
		
		txtProductPrice = new JTextField();
		double dPrice = product.getPrice();
		String sPrice = Double.toString(dPrice);
		txtProductPrice.setText(sPrice);
		txtProductPrice.setEditable(false);
		txtProductPrice.setEnabled(false);
		pnlForm.add(txtProductPrice, "4, 6, fill, default");
		txtProductPrice.setColumns(10);
		
		panel = new JPanel();
		FlowLayout flowLayout = (FlowLayout) panel.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		add(panel, BorderLayout.SOUTH);
		
		btnEditProduct = new JButton("Rediger produkt");
		btnEditProduct.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				callRootPane(2, 23, txtProductBarcode.getText());
			}
		});
		panel.add(btnEditProduct);
		
		btnDeleteProduct = new JButton("Slet Produkt");
		btnDeleteProduct.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				callRootPane(2, 24, txtProductBarcode.getText());
			}
		});
		panel.add(btnDeleteProduct);

		return pnlForm;
	}

}
